//
//  DKHomeLoanDetailView.m
//  DanKU
//
//  Created by 蓝鳍互娱 on 2023/12/7.
//

#import "DKHomeLoanDetailView.h"
#import "DKLoanDetailSigleCell.h"
@interface DKHomeLoanDetailView()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong) UITableView *homeLoanDetailTableView;
@end
@implementation DKHomeLoanDetailView
-(instancetype)init{
    if(self == [super init]){
        self.backgroundColor = UIColor.redColor;
        [self dk_addSubView];
    }
    return self;
}
- (void)dk_addSubView{
    self.homeLoanDetailTableView = [[UITableView alloc] init];
    self.homeLoanDetailTableView.backgroundColor = UIColor.whiteColor;
    self.homeLoanDetailTableView.delegate = self;
    self.homeLoanDetailTableView.dataSource = self;
    self.homeLoanDetailTableView.estimatedRowHeight = 0;
    self.homeLoanDetailTableView.estimatedSectionHeaderHeight = 0;
    self.homeLoanDetailTableView.estimatedSectionFooterHeight = 0;
    self.homeLoanDetailTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.homeLoanDetailTableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    self.homeLoanDetailTableView.showsVerticalScrollIndicator = NO;
    self.homeLoanDetailTableView.shouldIgnoreScrollingAdjustment = YES;
    self.homeLoanDetailTableView.shouldRestoreScrollViewContentOffset = YES;
    self.homeLoanDetailTableView.bounces = NO;
    [self addSubview:self.homeLoanDetailTableView];
    [self.homeLoanDetailTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.right.equalTo(@(DK_IsWidthScale(0)));
    }];
}
-(void)setDk_LoanDetailMdl:(DKLoanDetailModel *)dk_LoanDetailMdl{
    _dk_LoanDetailMdl = dk_LoanDetailMdl;
    [self.homeLoanDetailTableView reloadData];
}
#pragma mark -- UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _dk_LoanDetailMdl.pairs.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    DKLoanDetailPairsModel *dk_LoanDetailPairsMdl = _dk_LoanDetailMdl.pairs[indexPath.row];
    CGFloat keyWidth = [NSString getContentSize:dk_LoanDetailPairsMdl.key withFont:DK_FONT_Regular(17) withSize:CGSizeMake(CGFLOAT_MAX, DK_IsWidthScale(40))].width;
    CGFloat valueHeight = [NSString getContentSize:dk_LoanDetailPairsMdl.value withFont:DK_FONT_Regular(17) withSize:CGSizeMake(DK_SCREEN_W-DK_IsWidthScale(40)-keyWidth, CGFLOAT_MAX)].height;

    if((valueHeight < DK_IsWidthScale(40))){
        return DK_IsWidthScale(40);
    }else{
        return valueHeight+DK_IsWidthScale(10);
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    DKLoanDetailSigleCell *dk_LoanDetailSigleCell = [DKLoanDetailSigleCell authLoanDetailSigleCell:tableView];
    dk_LoanDetailSigleCell.dk_LoanDetailPairsMdl = _dk_LoanDetailMdl.pairs[indexPath.row];
    return dk_LoanDetailSigleCell;
}
@end
